package cdu.notFound.controller;

import cdu.notFound.model.User;
import cdu.notFound.service.MessService;
import cdu.notFound.service.impl.MessServiceImpl;
import cdu.notFound.utils.LoginVerify;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 删除一条消息
 */
@WebServlet("/RemoveMessServlet")
public class RemoveMessServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    if(request.getParameter("messid")==null || request.getParameter("messid").length()==0){
	        response.getWriter().print("false");
	        return;
	    }
	    Integer messId = Integer.parseInt(request.getParameter("messid"));
	    if (LoginVerify.isLogin(request)) {
	        User user = (User)request.getSession().getAttribute("loginUser");
	        int userId = user.getId();
			MessService messService = new MessServiceImpl();
			if(messService.removeOneMess(messId, userId));
			response.getWriter().print("success");
	    }else{
	        response.getWriter().print("false");
	    }
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
